/**
 * @authorwq1
 *2015-4-5
 */
package com.yuhj.ontheway.wq.adaptor;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.Bitmap;
import android.support.v4.util.LruCache;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.yuhj.ontheway.R;
import com.yuhj.ontheway.utils.ImageCache;
import com.yuhj.ontheway.wq.enty.Step;

/**
 * @author wq1
 *
 */
public class StepsAdapator extends BaseAdapter {
	private Context context;
	private Step[] stepList;
	private LruCache<String,Bitmap> lruCache;
	public StepsAdapator(Context context ) {
		super();
		this.context=context;
		 
		lruCache=ImageCache.GetLruCache(context);
	 
	}
	public void BindData( Step[] steps) {
		this.stepList=steps;
	}

	/* (non-Javadoc)
	 * @see android.widget.Adapter#getCount()
	 */
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return stepList.length;
	}

	/* (non-Javadoc)
	 * @see android.widget.Adapter#getItem(int)
	 */
	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	/* (non-Javadoc)
	 * @see android.widget.Adapter#getItemId(int)
	 */
	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	/* (non-Javadoc)
	 * @see android.widget.Adapter#getView(int, android.view.View, android.view.ViewGroup)
	 */
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHoleder viewHoleder =null;
		if (convertView==null) {
			viewHoleder =new ViewHoleder();
			convertView = LayoutInflater.from(context).inflate(R.layout.wangqu_dish_detail_item, null);
	//		viewHoleder.imageView=(ImageView) convertView.findViewById(R.id.wangqu_main_image);
			viewHoleder.stepconten=(TextView) convertView.findViewById(R.id.step_content);
			viewHoleder.stepimg=(ImageView) convertView.findViewById(R.id.step_img);
			convertView.setTag(viewHoleder);
		}else {
			viewHoleder = (ViewHoleder) convertView.getTag();
		}
		Step step=stepList[position];
		viewHoleder.stepconten.setText(step.getStep());
		viewHoleder.stepimg.setImageResource(R.drawable.defaultcovers);
		new ImageCache(context, lruCache,viewHoleder.stepimg,step.getImg(),"OnTheWay",800,400);
		
		return convertView;
	}
	private class ViewHoleder{
		private ImageView stepimg;
		private TextView stepconten;
		
	}

}
